from django.db import models
from copy import deepcopy

# 课程信息类
# 属性暂时按照南大信息门户爬取的数据命名 ——这么垃圾的命名绝对不是我干的
class CourseInfo(models.Model):

    title = models.CharField(max_length=255, verbose_name="课程名", default="")
    bh = models.CharField(max_length=32, verbose_name="课程编号", default="")
    place = models.CharField(max_length=255, verbose_name="校区", default="")
    classname = models.CharField(max_length=255, verbose_name="课程标识名", default="")
    time = models.CharField(
        max_length=255, verbose_name="上课时间", default=""
    )  # 原数据格式为字符串列表，这里转为字符串存储
    kkyx = models.CharField(max_length=64, verbose_name="开课学院", default="")
    name = models.CharField(max_length=64, verbose_name="老师", default="")
    nj = models.CharField(max_length=255, verbose_name="专业年级", default="")
    skyx = models.CharField(max_length=255, verbose_name="上课院系", default="")
    zcStr = models.CharField(max_length=64, verbose_name="神秘的二进制码", blank=True)

    # TODO: 等选课开始后才能获取的
    detail = models.TextField(verbose_name="课程详情", blank=True)

    # TODO: 后续可能还有课程评价相关的
    pass

    class Meta:
        verbose_name = "课程"
        verbose_name_plural = "课程"

    def __str__(self) -> str:
        return "{0}__{1}".format(self.classname, self.name)

    def toDict(self) -> dict:
        d = deepcopy(self.__dict__)
        d.pop("_state")
        return d
